package mc

import (
	"gitee.com/dreamwood/ez-go/db/mgo"
)

const (
	KnowledgeEventNew          = "study.KnowledgeNew"
	KnowledgeEventBeforeCreate = "study.KnowledgeBeforeCreate"
	KnowledgeEventBeforeUpdate = "study.KnowledgeBeforeUpdate"
	KnowledgeEventBeforeSave   = "study.KnowledgeBeforeCreate study.KnowledgeBeforeUpdate"
	KnowledgeEventAfterCreate  = "study.KnowledgeAfterCreate"
	KnowledgeEventAfterUpdate  = "study.KnowledgeAfterUpdate"
	KnowledgeEventAfterSave    = "study.KnowledgeAfterCreate study.KnowledgeAfterUpdate"
	KnowledgeEventDelete       = "study.KnowledgeDelete"

	KnowledgeAccessControlEvent = "study.KnowledgeAccessControl"
)

func GetKnowledgeConfig() *mgo.DocConfig {
	return Knowledge_Config
}

var Knowledge_Config *mgo.DocConfig

func init() {
	Knowledge_Config = NewKnowledgeConfig()
}

func NewKnowledgeConfig() *mgo.DocConfig {
	return &mgo.DocConfig{
		ContainerKey: "study.Knowledge",
		Fields: []string{
			"name", "subject", "grade",
		},
		RelationFields: []string{
			"subject", "grade",
		},
		RelationConfigs: map[string]*mgo.DocRelation{

			"subject": {
				Config:     GetSubjectConfig,
				DocName:    "Subject",
				JoinType:   "O",
				KeyInside:  "subjectId",
				KeyOutSide: "id",
			},

			"grade": {
				Config:     GetGradeConfig,
				DocName:    "Grade",
				JoinType:   "O",
				KeyInside:  "gradeId",
				KeyOutSide: "id",
			},
		},
		FieldFilter: map[string]*mgo.DocFieldFilter{
			"default": {
				Select: []string{},
				Omit:   []string{},
			},
		},
	}
}
